package com.swt.controller.W_controller;

import com.alibaba.fastjson.JSON;
import com.swt.domain.Club;
import com.swt.domain.User;
import com.swt.service.impl.W_impl.ClubServiceImpl;
import com.swt.service.impl.W_impl.UserServiceImpl;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.List;

@Controller
@RequestMapping("/ClubController")
public class ClubController {
    @Resource
    private ClubServiceImpl clubService;

    @Resource
    private UserServiceImpl userService;

    /**
     * 馆主登录校验
     * * */
    @RequestMapping("/login")
    @ResponseBody
    public String login(Club club, HttpServletRequest request){
        Club club1=clubService.checkLogin(club);
        if(club1!=null&&club1.getClubPassword().equals(club.getClubPassword())&&club1.getClubStatus().equals("已启用")){
            request.getSession().setAttribute("CLUB_SESSION_KEY",club1);
            return JSON.toJSONString("true");
        }else if(club1!=null&&club1.getClubPassword().equals(club.getClubPassword())&&club1.getClubStatus().equals("已禁用")){
            return JSON.toJSONString("已禁用");
        }else if(club1!=null&&club1.getClubPassword().equals(club.getClubPassword())&&club1.getClubStatus().equals("待审核")){
            return JSON.toJSONString("待审核");
        }
        return JSON.toJSONString("false");
    }
    /**
     * 馆主注册
     * */
    @RequestMapping("/register")
    @ResponseBody
    public String register(Club club,String vcode){
        System.out.println(club.getClubImg());
        Club club1=clubService.checkLogin(club);

        User user=new User();
        user.setUserPhone(club.getClubPhone());
        User user1=userService.checkLogin(user);


        if(club1==null&&user1==null){
            clubService.register(club);
            return JSON.toJSONString("true") ;
        }
        return JSON.toJSONString("false");
    }

    /**
     * 获取所有信息
     * */
    @RequestMapping("/listToAll")
    @ResponseBody
    public String listToAll(String page,Club club){

        System.out.println(page);
        List<Club>list=clubService.listToAll(Integer.parseInt(page),club);
        System.out.println(list);
        return JSON.toJSONString(list);
    }

    /**
     * 删除商家
     * */
    @RequestMapping("/delete")
    @ResponseBody
    public String delete(Club club){
        System.out.println(club.getClubLinkman());
        clubService.delete(club);
        return JSON.toJSONString("true");
    }

    /**
     * 禁用商家
     * */
    @RequestMapping("/stop")
    @ResponseBody
    public String stop(Club club){
        System.out.println(club.getClubStatus()+club.getClubPhone());
        clubService.stop(club);
        return JSON.toJSONString("true");
    }


}
